package userInterface;

import java.util.Date;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class FormItems 
	extends MIDlet
	implements CommandListener
{
	private Display mDisplay;
	private Form mFirstForm, mSecondForm, mThirdForm;
	private Command mExitCommand, mFirstCommand, mSecondCommand, mThirdCommand;

	protected void startApp() {
		if (mFirstForm == null) {
			// create a few commands
			mExitCommand = new Command("Exit", Command.EXIT, 0);
			mFirstCommand = new Command("First Form", Command.SCREEN, 0);
			mSecondCommand = new Command("Second Form", Command.SCREEN, 0);
			mThirdCommand = new Command("Third Form", Command.SCREEN, 0);
			
			// The first form 
			mFirstForm = new Form("First Form");
			mFirstForm.addCommand(mExitCommand);
			mFirstForm.addCommand(mFirstCommand);
			mFirstForm.addCommand(mSecondCommand);
			mFirstForm.addCommand(mThirdCommand);
			mFirstForm.setCommandListener(this);
			// create an image
			Image img = null;
			try { 
				img = Image.createImage("/healed.jpg");
			}
			catch (java.io.IOException ioe) {}
			catch (Exception e) {}
			// create an ImageItem
			ImageItem imgItem = new ImageItem("Heart", img,  
					ImageItem.LAYOUT_DEFAULT, "Healed heart!");
			mFirstForm.append(imgItem);
			// create a StringItem
			StringItem strItem = new StringItem("Heart", "This heart is yours!");
			mFirstForm.append(strItem);
			
			// The second form
			mSecondForm = new Form("First Form");
			mSecondForm.addCommand(mExitCommand);
			mSecondForm.addCommand(mFirstCommand);
			mSecondForm.addCommand(mSecondCommand);
			mSecondForm.addCommand(mThirdCommand);
			mSecondForm.setCommandListener(this);
			// create a text field
			TextField tf = new TextField("User name", "Some text", 20, TextField.ANY);
			mSecondForm.append(tf);
			// create a ChoiceGroup
			ChoiceGroup cg = new ChoiceGroup("Favorite food", ChoiceGroup.POPUP);
			cg.append("French fries", null);
			cg.append("Pasta", null);
			cg.append("Chinese food", null);
			cg.append("Thai food", null);
			mSecondForm.append(cg);
			// create a DateField
			long now = System.currentTimeMillis();
			DateField df = new DateField("Now", DateField.DATE_TIME);
			df.setDate(new Date(now));
			mSecondForm.append(df);
			
			// The third form
			mThirdForm = new Form("First Form");
			mThirdForm.addCommand(mExitCommand);
			mThirdForm.addCommand(mFirstCommand);
			mThirdForm.addCommand(mSecondCommand);
			mThirdForm.addCommand(mThirdCommand);
			mThirdForm.setCommandListener(this);
			// Create some Gauges
			Gauge gi = new Gauge("Interactive", true, 5, 2);
			Gauge gni = new Gauge("Non Interactive", false, Gauge.INDEFINITE, 
					Gauge.CONTINUOUS_RUNNING);
			mThirdForm.append(gi);
			mThirdForm.append(gni);
			
			// set the display
			mDisplay = Display.getDisplay(this);
		}
		mDisplay.setCurrent(mThirdForm);
	}
	protected void destroyApp(boolean arg0) {}
	protected void pauseApp() {}
	public void commandAction(Command c, Displayable d) {
		if (c == mExitCommand) {
			destroyApp(true);
			notifyDestroyed();
		} else if (c == mFirstCommand) {
			mDisplay.setCurrent(mFirstForm);
		} else if (c == mSecondCommand) {
			mDisplay.setCurrent(mSecondForm);
		} else if (c == mThirdCommand) {
			mDisplay.setCurrent(mThirdForm);
		}
	}
}
